/*-----------------------------------------------------------------------*/
/* Low level disk I/O module skeleton for FatFs     (C)ChaN, 2007        */
/*-----------------------------------------------------------------------*/
/* by grqd_xp                                                            */
/* This is a stub disk I/O module that acts as front end of the existing */
/* disk I/O modules and attach it to FatFs module with common interface. */
/*-----------------------------------------------------------------------*/
#include <string.h>
#include "diskio.h"
#include "sdcard.h"

#if (USE_SDCARD == 1)

/*-----------------------------------------------------------------------*/
/* Correspondence between physical drive number and physical drive.      */
/* Note that Tiny-FatFs supports only single drive and always            */
/* accesses drive number 0.                                              */

#define SECTOR_SIZE 512U

//u32 buff2[512/4];
/*-----------------------------------------------------------------------*/
/* Inidialize a Drive                                                    */

DSTATUS disk_initialize(
	BYTE drv				/* Physical drive nmuber (0..) */
	)
{
	return 0;
}


/*-----------------------------------------------------------------------*/
/* Return Disk Status                                                    */

DSTATUS disk_status(
	BYTE drv		/* Physical drive nmuber (0..) */
	)
{
	return 0;
}



/*-----------------------------------------------------------------------*/
/* Read Sector(s)                                                        */

DRESULT disk_read(
	BYTE drv,		/* Physical drive nmuber (0..) */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address (LBA) */
	BYTE count		/* Number of sectors to read (1..255) */
	)
{
	if (count == 1) SD_errno = SD_ReadBlock(sector << 9, (u32 *)(&buff[0]), SECTOR_SIZE);
	else SD_errno = SD_ReadMultiBlocks(sector << 9, (u32 *)(&buff[0]), SECTOR_SIZE, count);
	return SD_errno == SD_OK ? RES_OK : RES_ERROR;
}


/*-----------------------------------------------------------------------*/
/* Write Sector(s)                                                       */

#if _READONLY == 0
DRESULT disk_write(
	BYTE drv,			/* Physical drive nmuber (0..) */
	const BYTE *buff,	/* Data to be written */
	DWORD sector,		/* Sector address (LBA) */
	BYTE count			/* Number of sectors to write (1..255) */
	) {
	if (count == 1)	SD_errno = SD_WriteBlock(sector << 9, (u32 *)(&buff[0]), SECTOR_SIZE);
	else SD_errno = SD_WriteMultiBlocks(sector << 9, (u32 *)(&buff[0]), SECTOR_SIZE, count);
	return SD_errno == SD_OK ? RES_OK : RES_ERROR;
}
#endif /* _READONLY */



/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions                                               */

DRESULT disk_ioctl(
	BYTE drv,		/* Physical drive nmuber (0..) */
	BYTE ctrl,		/* Control code */
	void *buff		/* Buffer to send/receive control data */
	)
{
	return RES_OK;
}

#endif
